from prefect import flow, task
import subprocess

@task
def run_script_task(script_path):
    result = subprocess.run(['python', script_path], capture_output=True, text=True)
    print(result.stdout)
    if result.returncode != 0:
        raise Exception(f"Script failed: {result.stderr}")
    return result.returncode

@flow(name="My Script Flow")
def my_script_flow():
    # 这里可以调用多个task，并定义依赖
    status = run_script_task("/workspace/learning/python-learning/re-test.py")
    print(f"Script finished with status: {status}")

if __name__ == "__main__":
    my_script_flow()
